package com.my.code.identityhashmap;

import java.util.HashMap;
import java.util.IdentityHashMap;

/**
 * IdentityHashMap使用 == 比较对象是否相等
 */
public class TestIdentityMap {
    public static void main(String[] args) {
        IdentityHashMap<String, Integer> map = new IdentityHashMap<>();
        map.put("abc", 1);
        String key2 = new String("abc");
        map.put(key2, 2);

        System.out.println(map.size());//2
        System.out.println(map.get(key2));//2

        HashMap<String, Integer> hashMap = new HashMap<>();
        hashMap.put("abc", 1);
        hashMap.put(key2, 2);

        System.out.println("hashMap.size = " + hashMap.size());//1
        System.out.println(hashMap.get("abc"));//2
    }
}
